﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    CreateBannerAd
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Tạo mới banner quảng cáo</h2>
    <form action="<%= Url.Action("SaveBannerAd","BannerAd") %>" name="myform" method="post"
    enctype="multipart/form-data">
    <table>
        <tr>
            <td>
                Tên banner:
                <%=Html.TextBox("txtBannerId", (ViewData["BannerId"] == null ? "" : ViewData["BannerId"].ToString()), new { @class = "text hidden" })%>
            </td>
            <td>
                <%=Html.TextBox("txtBannerName", (ViewData["BannerName"] == null ? "" : ViewData["BannerName"].ToString()), new { @class = "text" })%>
            </td>
        </tr>
        <tr>
            <td>
                Banner
            </td>
            <td>
                <%string img = ViewData["bannerImg"] + ""; %>
                <%=Html.TextBox("txtBannerLink", (img == null ? "" : img.ToString()), new { @class = "text" })%>
                <%Response.Write(string.Format("<img src='{0}' id='txtBannerImg' name='txtBannerImg' />", (img == null ? "" : img.ToString()))); %>
            </td>
        </tr>
        <tr id="ex-file1">
            <td align="right" valign="middle" class="private_font_bold">
                Hình mình họa
            </td>
            <td>
                <input type="file" name="ex-file1" />
            </td>
        </tr>
        <tr>
            <td>
                Link to
            </td>
            <td>
                <%=Html.TextBox("txtBannerURL", (ViewData["BannerURL"] == null ? "" : ViewData["BannerURL"].ToString()), new { @class = "text" })%>
            </td>
        </tr>
        <tr>
            <td>
                Lượt Click
            </td>
            <td>
                <%=Html.TextBox("txtBannerClick", (ViewData["BannerClick"] == null ? "" : ViewData["BannerClick"].ToString()), new { @class = "text" })%>
            </td>
        </tr>
        <tr>
            <td>
                Ngày hiển thị
            </td>
            <td>
                <%
                    string start = ViewData["BannerStartDate"] + "";
                    string end = ViewData["BannerEndDate"] + "";
                %>
                <input class="txtBannerNgayBatDau" value="<%=start %>" name="txtBannerNgayBatDau"
                    id="txtBannerNgayBatDau" />
                <%--<input type="text" id="txtBannerNgayBatDau1" class="txtBannerNgayBatDau1" />--%>
            </td>
        </tr>
        <tr>
            <td>
                Ngày kết thúc
            </td>
            <td>
                <input class="txtBannerNgayKetThuc" value="<%=end %>" name="txtBannerNgayKetThuc"
                    id="txtBannerNgayKetThuc" />
            </td>
        </tr>
        <tr>
            <td>
                Vị trí xuất hiện
            </td>
            <td>
                <%
                    Response.Write("<select id='drlBannerViTri' name='drlBannerViTri' class='ddownlist' >");
                    string[] arr = new string[] { "All-Left-Top", "All-Left-Middle", "All-Left-Bottom", "All-Right-Top", "All-Right-Middle", "All-Right-Bottom", "News-Top", "All-Right-Corner" };
                    for (int i = 0; i < 8; i++)
                    {
                        if (ViewData["BannerPos"] == null)
                            Response.Write(string.Format("<option value='{0}'> {1}</option>'", (i + 1), arr[i]));
                        else
                            Response.Write(string.Format("<option selected='selected' value='{0}'> {1}</option>'", (i + 1), arr[i]));
                    }
                    Response.Write("</select>");
                %>
            </td>
        </tr>
        <tr>
            <td>
                Chọn Khách Hàng
            </td>
            <td>
                <%
                    Response.Write("<select id='drlBannerCus' name='drlBannerCus' class='ddownlist' >");
                    List<Customer> lstCus = new CustomerHelper().getAllCustomerOnDefault();
                    foreach (Customer cus in lstCus)
                    {
                        if (ViewData["BannerCus"] == null)
                            Response.Write(string.Format("<option value='{0}'> {1}</option>'", cus.CusID, cus.CusName));
                        else
                            if (cus.CusID == int.Parse(ViewData["BannerCus"].ToString()))
                            {
                                Response.Write(string.Format("<option selected='selected' value='{0}'> {1}</option>'", cus.CusID, cus.CusName));
                            }
                            else
                            {
                                Response.Write(string.Format("<option value='{0}'> {1}</option>'", cus.CusID, cus.CusName));
                            }
                    }
                    Response.Write("</select>");
                %>
            </td>
        </tr>
        <%--   <tr>
            <td>
                Giới thiệu
            </td>
            <td>
                <%=Html.TextArea("BannerIntro", (ViewData["BannerIntro"] == null ? "" : ViewData["BannerIntro"].ToString()), new { @class = "text text-area" })%>
            </td>
        </tr>--%>
    </table>
    <input type="submit" value="Save" id="button" class="hoicho_bt_submit_reg" style="width: 60px" />
    <script type="text/javascript">
        function currentDate() {
            var currentDate = new Date();
            var day = currentDate.getDate();
            var month = currentDate.getMonth() + 1;
            var year = currentDate.getFullYear();

            var d, m;
            if (month.toString().length == 1)
                m = "0" + month.toString();
            else m = month.toString();
            if (day.toString().length == 1)
                day = "0" + day.toString();
            else d = day.toString();

            var docs = document.getElementById("txtBannerNgayBatDau");
            var docs1 = document.getElementById("txtBannerNgayKetThuc");
            docs.value = d + "/" + m + "/" + year;
            docs1.value = d + "/" + m + "/" + year;


        }

        $('#txtBannerNgayBatDau').DatePicker({
            format: 'd/m/Y',
            date: $('#txtBannerNgayBatDau').val(),
            current: $('#txtBannerNgayBatDau').val(),
            starts: 1,
            position: 'r',
            onBeforeShow: function () {
                $('#txtBannerNgayBatDau').DatePickerSetDate($('#txtBannerNgayBatDau').val(), true);
            },
            onChange: function (formated, dates) {
                $('#txtBannerNgayBatDau').val(formated);
                // if ($('#closeOnSelect input').attr('checked')) {
                $('#txtBannerNgayBatDau').DatePickerHide();
                // var ff = document.getElementById("txtBannerNgayBatDau1");
                // ff.value = formated;
                //}
            }
        });

        $('#txtBannerNgayKetThuc').DatePicker({
            format: 'd/m/Y',
            date: $('#txtBannerNgayKetThuc').val(),
            current: $('#txtBannerNgayKetThuc').val(),
            starts: 1,
            position: 'r',
            onBeforeShow: function () {
                $('#txtBannerNgayKetThuc').DatePickerSetDate($('#txtBannerNgayKetThuc').val(), true);
            },
            onChange: function (formated, dates) {
                $('#txtBannerNgayKetThuc').val(formated);
                // if ($('#closeOnSelect input').attr('checked')) {
                $('#txtBannerNgayKetThuc').DatePickerHide();
                //}
            }
        });

    </script>
    <%-- <script type="text/javascript">
        $("#button").click(function () {
            var id = $("#txtBannerId").val();
            if (id == "")
                id = "0";
            var link = $("#txtBannerClick").val();
            var text = $("#txtBannerName").val();
            var img = "test";
            var pos = "8";
            var menid = "1";
            var status = "true";
            var pageid = "null";
            var startday = $('#txtBannerNgayBatDau').DatePickerGetDate("dd/mm/yyyy");
            var endday = $('#txtBannerNgayKetThuc').DatePickerGetDate("dd/mm/yyyy");
            var type = "flash";
            var cusid = "1";
            var form = document.forms["myform"];
            //var datastring = 'id=' + id + '&link=' + link + '&text=' + text + '&img=' + img + '&pos=' + pos + '&menid=' + menid + '&status=' + status + '&pageid=' + pageid + '&startday=' + startday + '&endday=' + endday + '&type=' + type + '&cusid=' + cusid;
            var datastring = "form=" + form + "&startday=" + startday + "&endday=" + endday;
            alert(datastring);
            $.ajax({
                type: "POST",
                url: "/BannerAd/SaveBannerAd",
                data: datastring,
                success: function (result) {
                    window.location = "Index?page=1";
                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        });
    </script>--%>
    <%
        if (Request.QueryString.Get("bannerId") == null)
        {
    %>
    <script type="text/javascript">
        currentDate();
    </script>
    <%} %>
    </form>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
</asp:Content>
